<?php

namespace App\Exports;

use App\Models\Courtyard;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Facades\Excel;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithDrawings;
class FangOwnerExport implements FromCollection,WithDrawings,ShouldAutoSize
{

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return DB::table('hospital')->limit(18)->get();
    }

    protected $invoices;

    protected $logo;

    public function drawings()
    {
        $img=public_path('hh.jpg');
        $result = [];
        $data = DB::table('hospital')->select('img')->limit(18)->get()->toArray();
        $res=array_column($data,'img');
        foreach ($res as $k => $v) {
            ${'drawing' . $k} = new Drawing();
            ${'drawing' . $k}->setName('logo');
            ${'drawing' . $k}->setDescription('this is my logo');
            //图片路径
            ${'drawing' . $k}->setPath(public_path($v));
            ${'drawing' . $k}->setHeight(100);
            //设置图片列
            ${'drawing' . $k}->setCoordinates('C' . $k);
            $result[] = ${'drawing' . $k};
        }
        return $result;
    }


}
